<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>用户注册</title>
<link rel="stylesheet" type="text/css" href="css/hui.css" />
</head>
<body>
<header class="hui-header"  style="margin-top:15px;">
    <div id="hui-back"></div>
    <h1>用户注册</h1>
</header>
<div class="hui-wrap">
    <div class="hui-center-title" style="margin-top:35px;"><h1>新用户注册</h1></div>
    <div style="margin:28px 15px; margin-bottom:15px;" class="hui-form" id="form1">
        <div class="hui-form-items">
            <input type="number" id="phone" class="hui-input hui-input-clear" placeholder="手机号码" checkType="phone" value="18100998888" checkMsg="请填写正确的手机号" />
        </div>
        <div class="hui-form-items">
            <input type="password" class="hui-input hui-pwd-eye" placeholder="登录密码" checkType="string" id="pwd" value="888888" checkData="6,20" checkMsg="密码应为6-20个字符" />
        </div>
        <div class="hui-form-items">
            <input type="password" class="hui-input hui-pwd-eye" placeholder="确认密码" checkType="sameWithId" checkData="pwd" value="888888" checkMsg="2次密码不一致" />
        </div>
        <div class="hui-form-items">
            <input type="nickname" id="nickname" class="hui-input hui-input-clear" placeholder="昵称" value="hcoder" checkType="string" checkData="2,10" checkMsg="昵称应为2-10个字符" />
        </div>
    </div>
    <div style="padding:28px 15px; padding-top:0px;">
        <button type="button" class="hui-button hui-button-large hui-primary" id="submit">注 册</button>
    </div>
</div>
<script type="text/javascript" src="js/hui.js" charset="UTF-8"></script>
<script src="js/hui-form.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
hui.formInit();//初始化表单提交
hui('#submit').click(function(){
	if(hui('#submit').buttonIsLoading()){return false;}//点击按钮时，按钮显示提交状态
    //验证
    var res = huiFormCheck('#form1');
    if(!res){return false;}
    //
    hui('#submit').loadingButton('提交中...');
    hui.postJSON(
    	'http://shop.hcoder.net/myApi.php',
		{act:"register", phone:hui('#phone').val(), pwd:hui('#pwd').val(), nickname:hui('#nickname').val()},
		function(res){
			if(res.msg == 'ok'){
				hui.toast("注册成功，请登录");
				var _self = plus.webview.currentWebview();
				setTimeout(function(){_self.close();}, 3000);
				return;
			}else if(res.msg == 'have'){
				hui('#submit').resetLoadingButton();
				hui.toast("手机号码已被注册");
				return;
			}
			hui('#submit').resetLoadingButton();
			hui.toast("服务器忙，请重试");
		}
    );
});
</script>
</body>
</html>